Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite section on Portability for Relational Databases #469

Merged
merged 2 commits into from
Feb 22, 2024

Conversation

gavinking
Copy link
Contributor

I was not happy with section 7.1, so here's what I think it should say.

At least, something like this.

Thoughts?

@gavinking
Copy link
Contributor Author

By the way, at this point, with so many of the foundations already in place, it would take me approximately an hour or two to add @Persist, @Merge, @Refresh, @Lock, @Remove, @Detach, @JPQL and @SQL annotations to Jakarta Data, thus providing fully portable support for JPA.

Just a thought. I know we said we weren't going to do it in this release, but we've come a long way since then.

Copy link
Contributor

@njr-11 njr-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updates in this pull look good, and it also does a nice job of preserving the important parts of what was previously there.

in particular, remove language about persistence contexts being
non-stateful, since JPA itself does not currently allow this
@gavinking
Copy link
Contributor Author

I have pushed a second commit, which reworks section 6.4 on interop with JPA.

This does change semantics, since the current version says that JPA-backed repositories must by stateless, but JPA doesn't support that.

TANGENTIAL: the TCK has a test repository (ee.jakarta.tck.data.standalone.persistence.Catalog) which I believe is intended for use with JPA-backed providers. Now, this test is perfectly fine for my Hibernate-based implementation since I have stateless sessions. It's not, in my opinion, appropriate for a generic JPA-backed provider. This problem is easily fixed if we do #470.

@otaviojava otaviojava merged commit 88fc5d1 into jakartaee:main Feb 22, 2024
4 checks passed

Repository operations must behave as though backed by a stateless Entity Manager in that persistence context is not preserved across the end of repository methods. All entities that are returned by repository methods must be in a detached state such that modifications to these entities are not persisted to the database unless the application explicitly invokes a `Save` or `Update` life cycle method for the entity.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize the stateless EntityManager didn't make it into Jakarta Persistence 3.2, but it would be nice to be able to standardize the behavior in anticipation of it. I think it should be possible to simulate the behavior with what is currently in the Jakarta Persistence API unless I'm missing something. Although I suppose it will be somewhat inefficient to do so. I don't really like leaving it so unclear in the Jakarta Data spec, which leaves the user wondering what behavior they will end up with, or maybe assuming a behavior that is not the right one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so as I've argued elsewhere the implementations don't in principle need to wait for permission from the JPA spec to offer stateless sessions. So if you want me put back in something about this approach, that's totally fine, but I want it to be clear that you can also have a repository backed by a regular stateful session, and the previous language sounded like it was disallowing that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @otaviojava already merged this one on the basis of my review of the first commit. Apparently git doesn't reset the review status when more commits are added. We will need to ensure this discussion doesn't get lost because the change has been applied already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this is easier to specify if I can talk about it in terms of @Insert vs @Persist if you get my drift.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @otaviojava already merged this one on the basis of my review of the first commit. Apparently git doesn't reset the review status when more commits are added. We will need to ensure this discussion doesn't get lost because the change has been applied already.

Don't worry Nathan I can write this up tonight if we agree on the basic idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njr-11 So how about something like this:

A Jakarta Data provider which supports Jakarta Persistence entities bearing the annotation jakarta.persistence.Entity may support either or both of the following repository styles:

  • A repository might be backed by a Jakarta Persistence EntityManager with a stateful persistence context. The lifecycle operations of the repository are annotated with the Jakarta Persistence-specific annotations @Persist, @Merge, and friends, and follow the semantics of the corresponding standard operations of jakarta.persistence.EntityManager. In particular, the repository observes the semantics of the Jakarta Persistence CascadeType.
  • Alternatively, a repository might by "stateless", in the sense that it does not maintain a persistence context which outlives the invocation of a single repository method. The lifecycle operations of this kind of repository are annotated @Insert, @Delete, or @Update, and adhere to the usual semantics of these annotations. In particular, these operations never cascade to related entities.

That's just a first cut, of course.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I did not see this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants